package com.sq.auth.domain.service.impl;

import com.sq.auth.domain.bo.AuthRolePermissionBO;
import com.sq.auth.domain.service.AuthRolePermissionDomainService;
import com.sq.auth.infra.basic.entity.AuthRolePermission;
import com.sq.auth.infra.basic.service.AuthRolePermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author quan
 */
@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {

    @Resource
    private AuthRolePermissionService authRolePermissionService;

    @Override
    public boolean add(AuthRolePermissionBO authRolePermissionBO) {
        List<Long> permissionIdList = authRolePermissionBO.getPermissionIdList();
        Long roleId = authRolePermissionBO.getRoleId();
        List<AuthRolePermission> authRolePermissionList = permissionIdList.stream().map(permissionId -> {
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setPermissionId(permissionId);
            authRolePermission.setRoleId(roleId);
            return authRolePermission;
        }).toList();
        int insert = authRolePermissionService.batchInsert(authRolePermissionList);
        return insert > 0;
    }
}
